package cmd

import (
	"context"
	"video-api/utility/metrics"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
)

var (
	Prometheus = &gcmd.Command{
		Name:        "prometheus",
		Brief:       "start prometheus server",
		Description: "this is the command entry for starting all server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			s := g.Server("prometheus")
			// 添加 Prometheus 监控路由
			s.Group("/metrics", func(group *ghttp.RouterGroup) {
				group.ALL("/", func(r *ghttp.Request) {
					r.Response.Header().Set("Content-Encoding", "identity") // 禁用 gzip
					metrics.PrometheusHandler().ServeHTTP(r.Response.Writer, r.Request)
				})
			})
			s.Run()
			return nil
		},
	}
)
